//
//  BaseSQLModel.swift
//  App
//
//  Created by 汤泽川 on 2019/3/25.
//

import Foundation
import Vapor
import FluentMySQL

public typealias SQLModelType = MySQLModel & Migration & Content

//声明协议
protocol BaseModel: SQLModelType {
    
    static var entity: String { get }
    
    static var createdAtKey: TimestampKey? { get }
    static var updatedAtKey: TimestampKey? { get }
    
    var createdAt: Date? { get set }
    var updatedAt: Date? { get set }
}

//默认实现
extension BaseModel {
    
    var deletedAt: Date? { return nil }
    
    static var entity: String { return self.name + "s" }
    
    static var createdAtKey: TimestampKey? { return \Self.createdAt }
    static var updatedAtKey: TimestampKey? { return \Self.updatedAt }
}

